<?php

/*
To test uncomment below code and comment line no. 18,19,20,43,47 & 49.

$username = 'username';
$password = 'password';
$shiftToModify = 1;
$fieldToModify = 'Date';
$newValue = 2;

$result = modifyShift($username,$password,$shiftToModify,$fieldToModify,$newValue);
echo(json_encode($result));
*/

function modifyShift($authUser, $authUserPass, $shiftToModify, $fieldToModify, $newValue)
{
      if (checkAuthorization($authUser, $authUserPass) != true){
      	return array(ErrorCode::authFailRead);
      }

      $conn = mysql_connect('localhost','root','');
      mysql_select_db('paradigmShift_DEV');

      if(!$conn)
      {
            die('Could not connect: ' . mysql_error());
            return array(ErrorCode::sysError);
      }

      if ($fieldToModify == "Employee"){
            $sql = "UPDATE RoleDates SET empID = '$newValue' WHERE roleID = '$shiftToModify'";
      } else if ($fieldToModify == "Date"){
            $sql = "UPDATE RoleDates SET dateID = '$newValue' WHERE roleID = '$shiftToModify'";
      } else if ($fieldToModify == "Role"){
            $sql = "UPDATE RoleDates SET RoleID = '$newValue' WHERE roleID = '$shiftToModify'";
      } else if ($fieldToModify == "Status"){
            $sql =  "UPDATE RoleDates SET shiftStatus = '$newValue' WHERE roleID = '$shiftToModify'";
      } else if ($fieldToModify == "StartTime"){
            $sql = "UPDATE RoleDates SET startTime = '$newValue' WHERE roleID = '$shiftToModify'";
      } else if ($fieldToModify == "EndTime"){
            $sql = "UPDATE RoleDates SET endTime = '$newValue' WHERE roleID = '$shiftToModify'";
      } else {
      	return array('ErrorCode::failUpdate');
      }

      if (mysql_query($sql)){
            return array('ErrorCode::successUpdate');
      } else {
            return array('ErrorCode::failDelete');
      }
      mysql_close($conn);
}
?>